using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using BusinessLayer;
using EntityLayer;
using InfraStructureLayer;

public partial class articles_Default : SFPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected bool sfrArticles_NeedsDataSource()
    {
        busArticles insBusArticles = new busArticles();
        DataTable insDataTableArticles = null;

        if (this.QueryStringArchive.ToString() == "")
        {
            if (Request.QueryString["Archive"] != null && Request.QueryString["Archive"] != "")
            {
                this.QueryStringArchive = Request.QueryString["Archive"];
            }
        }
        if (this.QueryStringCategory.ToString() == "")
        {
            if (Request.QueryString["Category"] != null && Request.QueryString["Category"] != "")
            {
                this.QueryStringCategory = Request.QueryString["Category"];
            }
        }

        if (this.QueryStringArchive=="" && this.QueryStringCategory=="")
        {
            insDataTableArticles = insBusArticles.SelectArticlesByLanguageId();
        }
        else if (this.QueryStringCategory != "")
        {
            entArticles insEntArticles = new entArticles();
            string categoryId = new Crypto().DecryptURL(this.QueryStringCategory);
            insDataTableArticles = insBusArticles.SelectArticlesByLanguageIdAndCategoryId(Convert.ToInt32(categoryId));
        }
        else
        {
            entArticles insEntArticles = new entArticles();
            string archive = new Crypto().DecryptURL(this.QueryStringArchive);
            string year = archive.Substring(0, 4);
            string month = "";
            if (archive.Substring(4, 2).StartsWith("0"))
            {
                month = archive.Substring(5, 1);
            }
            else
            {
                month = archive.Substring(4, 2);
            }
            insEntArticles.PublishDate = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), 1);
            insDataTableArticles = insBusArticles.SelectArticlesByLanguageIdAndYearAndMonth(insEntArticles);
        }
        if (insBusArticles.HasErrors)
        {
            MessageBoxShow(insBusArticles);
            return true;
        }

        sfrArticles.SetData(insDataTableArticles);
        return insBusArticles.HasErrors;
    }
    protected string GenerateUrl(object obj)
    {
        return "~/" + CurrentContext.Language + "/Articles/" + new Crypto().EncryptURL(obj.ToString()) + ".aspx";
    }
}
